package com.implicit.intent;

import com.example.todolist.R;

import android.R.menu;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class call_phone extends Activity {
	
	Button m_cmd_btn0,m_cmd_btn1, m_cmd_btn2, m_cmd_btn3;
	Button m_cmd_btn4,m_cmd_btn5, m_cmd_btn6, m_cmd_btn7;
	Button m_cmd_btn8,m_cmd_btn9, m_cmd_btn_start, m_cmd_btn_clear;
	TextView m_tv_number;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.cell_phone);
		
		m_tv_number = (TextView) findViewById(R.id.m_tv_display_number);
		m_cmd_btn0 = (Button) findViewById(R.id.m_cmd_button0);
		m_cmd_btn1 = (Button) findViewById(R.id.m_cmd_button1);
		m_cmd_btn2 = (Button) findViewById(R.id.m_cmd_button2);
		m_cmd_btn3 = (Button) findViewById(R.id.m_cmd_button3);
		m_cmd_btn4 = (Button) findViewById(R.id.m_cmd_button4);
		m_cmd_btn5 = (Button) findViewById(R.id.m_cmd_button5);
		m_cmd_btn6 = (Button) findViewById(R.id.m_cmd_button6);
		m_cmd_btn7 = (Button) findViewById(R.id.m_cmd_button7);
		m_cmd_btn8 = (Button) findViewById(R.id.m_cmd_button8);
		m_cmd_btn9 = (Button) findViewById(R.id.m_cmd_button9);
		m_cmd_btn_start = (Button) findViewById(R.id.m_cmd_button_start);
		m_cmd_btn_clear = (Button) findViewById(R.id.m_cmd_button_clear);
		
		m_cmd_btn0.setOnClickListener(this.appenString("0"));
		m_cmd_btn1.setOnClickListener(this.appenString("1"));
		m_cmd_btn2.setOnClickListener(this.appenString("2"));
		m_cmd_btn3.setOnClickListener(this.appenString("3"));
		m_cmd_btn4.setOnClickListener(this.appenString("4"));
		m_cmd_btn5.setOnClickListener(this.appenString("5"));
		m_cmd_btn6.setOnClickListener(this.appenString("6"));
		m_cmd_btn7.setOnClickListener(this.appenString("7"));
		m_cmd_btn8.setOnClickListener(this.appenString("8"));
		m_cmd_btn9.setOnClickListener(this.appenString("9"));
		m_cmd_btn_start.setOnClickListener(this.appenString("*"));
		
		m_cmd_btn_clear.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				m_tv_number.setText("");
			}
		});
		
	}
	public OnClickListener appenString(final String ip_str) {
		return new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				m_tv_number.append(ip_str);
			}
		};
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		super.onCreateOptionsMenu(menu);
		menu.add(0, Menu.FIRST,0, "Exit")
		.setIcon(android.R.drawable.ic_delete);
		return true;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
		case Menu.FIRST:
			finish();
			break;
		}
		return false;
	}
}
